$('#nav').click(function(){
    $('#sidebar ul').slideToggle(100)
});
var V=0;
$('#sidebar ul li').hover(function(){
    V=$(this).index();
    $('#bottom ol').eq(V).addClass('subnav').siblings().removeClass('subnav')
},function(){
    $('#bottom ol').removeClass('subnav')
});
$('#bottom ol').hover(function(){
    $('#bottom ol').eq(V).addClass('subnav').siblings().removeClass('subnav');
},function(){
    $('#bottom ol').removeClass('subnav')
});


(function ($, win) {
    var Star = function (selector, index) {
        this.index = index;
        this.stars = $(selector);
        this.list = this.stars.find('span');
        this.on = 'on';
        this.setStarByIndex(this.index);
        this.hoverEvent();
        this.clickEvent();
    };
    $.extend(true, Star.prototype, {
        hoverEvent: function () {
            var _this = this;
            this.list.hover(function () {
                _this.setStarByIndex($(this).index())
            }, function () {
                _this.setStarByIndex(_this.index)
            })
        },
        clickEvent: function () {
            var _this = this;
            this.list.click(function () {
                _this.index = $(this).index();
            })
        },
        setStarByIndex: function (index) {
            if (index < 0) {
                this.list.removeClass(this.on);
            } else {
                this.list.eq(index).addClass(this.on).prevAll().addClass(this.on);
                this.list.eq(index).nextAll().removeClass(this.on);
            }
        }
    });
    Star.init = function (lists, index) {
        var _this = this;
        lists.each(function (key, item) {
            new _this(item, index)
        })
    };
    win['Star'] = Star;
})(jQuery, window);
Star.init($('.stars'), -1);



$('#star span').click(function(){
    var i=$(this).index();
    ++i;
    $('#star i').text(i)

});

var timer=null;
$('#text ').keyup(function(){
    if(timer){
        clearTimeout(timer)
    }
    timer= setTimeout(function(){
        var textLength=$('#text').val().length;
        $('#word').text(500-textLength)
    },300)
});

